package com.lanou.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.bean.Account;
import com.lanou.bean.Cost;
import com.lanou.mapper.AccountMapper;
import com.lanou.mapper.CostMapper;
import com.lanou.mapper.ServiceMapper;
import com.lanou.service.ServiceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/13.
 */
@Service
public class ServiceServiceImpl implements ServiceService {
    @Resource
    private ServiceMapper serviceMapper;

    @Resource
    private CostMapper costMapper;

    @Resource
    private AccountMapper accountMapper;

    @Override
    public List<com.lanou.bean.Service> allservice() {
        return serviceMapper.selectall();
    }

    @Override
    public List<com.lanou.bean.Service> selectCostById(Integer costId) {
        return serviceMapper.selectCostById(costId);
    }

    @Override
    public PageInfo<com.lanou.bean.Service> queryCostByPage(Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 3 : pageSize;
        PageHelper.startPage(pageNo, pageSize);
        List<com.lanou.bean.Service> accountList = serviceMapper.selectall();
        PageInfo<com.lanou.bean.Service> costPageInfo = new PageInfo<com.lanou.bean.Service>(accountList);
        System.out.println(costPageInfo);
        return costPageInfo;
    }

    @Override
    public PageInfo<com.lanou.bean.Service> queryServiceByPage(Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null?1:pageNo;
        pageSize = pageSize == null?3:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<com.lanou.bean.Service> serviceList = serviceMapper.selectall();
        PageInfo<com.lanou.bean.Service> servicePageInfo = new PageInfo<com.lanou.bean.Service>(serviceList);
        System.out.println(servicePageInfo);
        return servicePageInfo;
    }

    @Override
    public void addservice(com.lanou.bean.Service service) {
        serviceMapper.addservice(service);
    }

    @Override
    public void deleteservice(Integer serviceid) {
        serviceMapper.deleteservice(serviceid);
    }

    @Override
    public String osUsernameisexist(String osUsername) {
        return serviceMapper.osUsernameisexist(osUsername);
    }

    @Override
    public void updateStatusByServiceId(@Param("status") String status, @Param("serviceId") Integer serviceId) {
        serviceMapper.updateStatusByServiceId(status, serviceId);
    }

    @Override
    public List<com.lanou.bean.Service> findServiceById(Integer serviceId) {
        return serviceMapper.findServiceById(serviceId);
    }

    @Override
    public void updateCostIdByServiceId(Integer costId, Integer serviceId) {
        serviceMapper.updateCostIdByServiceId(costId, serviceId);
    }

    @Override
    public List<com.lanou.bean.Service> selectByServiceId(Integer serviceId) {
        return serviceMapper.selectByServiceId(serviceId);
    }

}
